

*set working directory
cd ".."

************************************************************************************************
*Figure 4: Bank LPI Cross-section
************************************************************************************************

use "data_intermediate/bank_ltisample_haircutrobust_new.dta", clear

collapse (mean) lpi , by (rssd)

replace lpi=lpi*10000

histogram lpi, fraction  xtitle("Liquidity Provision Index") ytitle("Fraction") start(0)   ylabel( , nogrid) bgcolor(white)  fcolor(blue) lcolor(black)  graphregion(color(white)) 
graph export "output/ltibankcrosssection.pdf", replace
   
	   
************************************************************************************************
*Figure 3: Fund LPI Cross-section 
************************************************************************************************
use "data_intermediate/fund_ltisample_haircutrobust_new.dta", clear

 
collapse (mean) lpi, by (crsp_portno) 

replace lpi=lpi*10000


histogram lpi,    fcolor(maroon) lcolor(black) frac xtitle("Liquidity Provision Index")  ylabel(,nogrid) bgcolor(white)  graphregion(color(white)) 
graph export "output/ltifundcrosssection_baseline.pdf", replace


************************************************************************************************
*Figure 5: Fund and Bank Weighted Time Series
************************************************************************************************

use "data_intermediate/bank_ltisample_haircutrobust_new.dta", clear

drop if quarter==.

replace assetstotal=. if lpi==. 
replace lpi=. if assetstotal==.
gen total_lpi=lpi*assetstotal 

collapse (sum) total_lpi assetstotal, by ( tq year quarter) 

gen w_lpi=total_lpi /assetstotal

sort tq

save "data_intermediate/banks_ltitimeseries.dta", replace


use "data_intermediate/fund_ltisample_haircutrobust_new.dta", clear

drop if quarter==.

replace assetstotal=. if lpi==. 
replace lpi=. if assetstotal==.

gen total_lpi=lpi*assetstotal 

collapse (sum) total_lpi assetstotal, by (year quarter) 

gen w_lpi=total_lpi /assetstotal

rename w_lpi fund_w_lpi

merge 1:1 year quarter using "data_intermediate/banks_ltitimeseries.dta"
drop _merge 

rename w_lpi bank_w_lpi

replace fund_w_lpi=fund_w_lpi*10000
replace bank_w_lpi=bank_w_lpi*10000

twoway line fund_w_lpi tq, lcolor("maroon") ||  line bank_w_lpi  tq, lcolor("navy")  || , ylabel(, nogrid)  ytitle("Liquidity Provision Index") xtitle("") ylabel(, nogrid) graphregion(color(white)) bgcolor(white) legend( label(1 "Funds") label(2 "Banks") region(col(white)))
graph export "output/lti_timeseries.pdf", replace


